From: Andrew Cooper Date: Tue, 14 Jul 2015 09:38:46 +0000 (+0100) Subject: tools/libxl: Fix libxl__carefd_opened() to be more useful with an invalid fd X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~2810 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=a8d23067bc0eb4d50626caea64fe9c924b66f77a;p=xen.git tools/libxl: Fix libxl__carefd_opened() to be more useful with an invalid fd In the case that fd is -1, preserve errno and don't attempt to set CLOEXEC. Note that the implementation can still fail, as it ignores fcntl() errors and may not set CLOEXEC properly. Update the documentation accordingly until it is fixed. Signed-off-by: Andrew Cooper CC: Ian Campbell CC: Ian Jackson CC: Wei Liu Acked-by: Ian Jackson --- Fixing the fnctl() error issue involves more TUITs than I currently have. New in v4 --- diff --git a/tools/libxl/libxl_fork.c b/tools/libxl/libxl_fork.c index 44866872b9..024c1e2fb9 100644 --- a/tools/libxl/libxl_fork.c +++ b/tools/libxl/libxl_fork.c @@ -112,9 +112,12 @@ libxl__carefd *libxl__carefd_record(libxl_ctx *ctx, int fd) libxl__carefd *libxl__carefd_opened(libxl_ctx *ctx, int fd) { libxl__carefd *cf = 0; + int saved_errno = errno; - cf = libxl__carefd_record(ctx, fd); + if (fd >= 0) + cf = libxl__carefd_record(ctx, fd); libxl__carefd_unlock(); + errno = saved_errno; return cf; } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 3f1fed847e..5d3499eaef 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2189,7 +2189,7 @@ _hidden void libxl__carefd_unlock(void); _hidden libxl__carefd *libxl__carefd_record(libxl_ctx *ctx, int fd); /* Combines _record and _unlock in a single call. If fd==-1, - * still does the unlock, but returns 0. Cannot fail. */ + * still does the unlock, but returns 0. */ _hidden libxl__carefd *libxl__carefd_opened(libxl_ctx *ctx, int fd); /* Works just like close(2). You may pass NULL, in which case it's